package com.example.firstdemo.ui.screens.pages.addProblem.addProblem.addDescription

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable

@Serializable
object AddDescription

fun NavGraphBuilder.addDescriptionDestination(
    padding: PaddingValues = PaddingValues(0.dp),
    navController: NavController
) {
    composable<AddDescription> {
        AddDescriptionScreen(
            padding = padding,
            onBack = navController::popBackStack,
            onConfirm = {
                CoroutineScope(Dispatchers.IO).launch {
                    AddDescriptionEvent.emit(it)
                    delay(500)
                    withContext(Dispatchers.Main) {
                        navController.popBackStack()
                    }
                }
            }
        )
    }
}

fun NavController.navigateToAddDescription() {
    navigate(AddDescription)
}